package io.github.stary1993.kite.auth.endpoint;

import io.github.stary1993.kite.captcha.support.simple.SimpleImageCaptcha;
import io.github.stary1993.kite.captcha.support.simple.SimpleImageCaptchaType;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 验证码相关的接口
 *
 * @author lengleng
 * @date 2022/6/27
 */
@RestController
@RequestMapping("/code")
@RequiredArgsConstructor
public class ImageCodeEndpoint {

	private final SimpleImageCaptcha simpleImageCaptcha;

	/**
	 * 创建图形验证码
	 */
	@SneakyThrows
	@GetMapping("/image")
	public void image(String timestamp, HttpServletResponse response) {
		simpleImageCaptcha.out(SimpleImageCaptchaType.spec, timestamp, response.getOutputStream());
	}

}
